<!-- 投诉用户 -->
<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="4">
					<a-form-item label="手机号：" name="mobile" >
						<a-input v-model:value="searchFormState.mobile" placeholder="请输入投诉用户手机号" clearable />
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-form-item label="身份证号" name="idCard">
						<a-input v-model:value="searchFormState.idCard" placeholder="请输入身份证号" clearable />
					</a-form-item>
				</a-col>
				<a-form-item label="用户姓名" name="userName">
					<a-input v-model:value="searchFormState.userName" placeholder="请输入用户姓名" clearable />
				</a-form-item>
				<a-col :span="6">
					<a-button type="primary" @click="table.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:scroll="{ x: 'max-content' }"
		>
			<template #operator class="table-operator">
				<a-space >
					<a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('complaintAdd')">
						<template #icon>
							<plus-outlined />
						</template>
						新增
					</a-button>
				</a-space>
				<a-space class="m-l-24">
					<a-button type="primary" @click="uploadExcel.openUpload()" v-if="hasPerm('complaintAdd')">
						<template #icon>
							<plus-outlined />
						</template>
						导入
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'imageUrl'">
					<a :href="record.imageUrl" :target="record.imageUrl">{{ record.imageUrl }}</a>
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="formRef.onOpen(record)" v-if="hasPerm('complaintEdit')">编辑</a>
						<a-divider type="vertical" v-if="hasPerm(['complaintDelete', 'complaintEdit'], 'and')" />
						<a-popconfirm title="确定要删除吗？" @confirm="deleteinfo(record)">
							<a-button type="link" danger size="small" v-if="hasPerm('complaintDelete')">删除 </a-button>
						</a-popconfirm>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="table.refresh(true)" />
	<Upload ref="uploadExcel" @successful="table.refresh(true)" />

</template>

<script setup name="complaint">
	import complaintApi from '@/api/tjzy/complaint/complaintApi'
	import Form from '@/views/tjzy/complaint/form.vue'
	import Upload  from '@/views/tjzy/complaint/upload.vue'
	const searchFormState = reactive({
		mobile: '',
		idCard: '',
		userName: ''
	})
	const uploadExcel =	ref()
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		table.value.refresh(true)
	}
	const columns = [
		{
			title: '投诉用户手机号',
			dataIndex: 'mobile',
			align: 'center'
		},
		{
			title: '身份证号码',
			dataIndex: 'idCard',
			align: 'center'
		},
		{
			title: '用户姓名',
			dataIndex: 'userName',
			align: 'center'
		},
		{
			title: '投诉内容',
			dataIndex: 'complainContent',
			align: 'center',
			width: 500
		},
		{
			title: '投诉金额',
			dataIndex: 'complainAmount',
			align: 'center'
		},
		{
			title: '投诉重要程度',
			dataIndex: 'complainImportant',
			align: 'center'
		},
		{
			title: '平台项目',
			dataIndex: 'platformProject',
			align: 'center'
		},
		{
			title: '逾期时间',
			dataIndex: 'overdueTime',
			align: 'center'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: 150,
			fixed: 'right'
		}
	]
	const table = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const loadData = (parameter) => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		return complaintApi.complaintPage(Object.assign(parameter, searchFormParam)).then((data) => {
			return data
		})
	}

	// 删除
	const deleteinfo = (record) => {
		let params = [
			{
				id: record.id
			}
		]
		complaintApi.complaintDelete(params).then(() => {
			table.value.refresh(true)
		})
	}
</script>

<style scoped></style>
